GSA <- read.table('prs_Compulsive_phewas_gsa_result_n31948.csv', head=T, sep = ',')[,c(1,9:11,19,20)]
GSA$prev.GSA <- GSA$n_cases/GSA$n_total
MEGA <- read.table('prs_Compulsive_phewas_mega_result_n9855.csv', head=T, sep = ',')[,c(1,9:11,19,20)]
MEGA$prev.MEGA <- MEGA$n_cases/MEGA$n_total
BioVU <- read.table('../BioVU_includingMHC/cov0/Comp_Factor.txt_PheWAS_results_slurm_cov0.txt', head=T, sep='\t')[,c(1,9:11)]
BioVU$prev.BioVU <- BioVU$n_cases/BioVU$n_total
BioVU$phecode <- as.numeric(gsub("X", "", BioVU$phenotype))

GSA_MEGA_BioVU <- merge(merge(GSA, MEGA[,-c(5,6)], by = 'phecode'), BioVU, by = 'phecode')

write.table(GSA_MEGA_BioVU, 'GSA_MEGA_BioVU.txt', row.names = F, sep = ',')

# plot
gsa <- ggplot(GSA_MEGA_BioVU, aes(x = round(prev.GSA,2), y = round(prev.BioVU,2), color = group)) +
geom_point(aes(label = description), size = 0.3) + facet_wrap(vars(group)) + geom_abline(intercept = 0, slope = 1, color = 'gray') + guides(group="none") + 
theme_classic() 
## Warning: Ignoring unknown aesthetics: label
ggplotly(gsa, width = 1000, height = 1000)
gsa_cc <- ggplot(GSA_MEGA_BioVU, aes(x = n_cases.x, y = n_controls.x, color = group)) +
geom_point(aes(label = description), size = 0.3) + facet_wrap(vars(group)) + guides(group="none") +
theme_classic() 
## Warning: Ignoring unknown aesthetics: label
ggplotly(gsa_cc, width = 1000, height = 1000)
mega_cc <- ggplot(GSA_MEGA_BioVU, aes(x = n_cases.y, y = n_controls.y, color = group)) +
geom_point(aes(label = description), size = 0.3) + facet_wrap(vars(group)) + guides(group="none") +
theme_classic() 
## Warning: Ignoring unknown aesthetics: label
ggplotly(mega_cc, width = 1000, height = 1000)
biovu_cc <- ggplot(GSA_MEGA_BioVU, aes(x = n_cases, y = n_controls, color = group)) +
geom_point(aes(label = description), size = 0.3) + facet_wrap(vars(group)) + guides(group="none") +
theme_classic() 
## Warning: Ignoring unknown aesthetics: label
ggplotly(biovu_cc, width = 1000, height = 1000)